//
//  FindDetailCell.m
//  geiTA
//
//  Created by 曲丹阳 on 14-11-22.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "FindDetailCell.h"
#import "UIImageView+WebCache.h"

@implementation FindDetailCell
- (void)dealloc
{
    [_myimage release];
    [_mylabel release];
    [self removeObserver:self forKeyPath:@"model"];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.myimage = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.myimage.layer.cornerRadius = 10;
        self.myimage.layer.masksToBounds = YES;
        
        self.mylabel = [[UILabel alloc] initWithFrame:CGRectZero];
        [self.mylabel setTextColor:[UIColor whiteColor]];
        [self.mylabel setFont:[UIFont boldSystemFontOfSize:17.0]];
        
        [self.contentView addSubview:_myimage];
        [self.myimage addSubview:_mylabel];
        
        [self addObserver:self forKeyPath:@"model" options:NSKeyValueObservingOptionNew context:nil];
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [self.myimage setFrame:CGRectMake(13, 5, [[UIScreen mainScreen] applicationFrame].size.width - 26, [[UIScreen mainScreen] applicationFrame].size.height / 5)];
    
    [self.mylabel setFrame:CGRectMake(0, self.frame.size.height / 1.5f, _myimage.frame.size.width, 30)];
    
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"model"]) {
        [self.myimage setImageWithURL:[NSURL URLWithString:_model.cover_image_url]];
        [self.mylabel setText:_model.title];
        
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
